package com.hx.strategy.promotion;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author Huathy
 * @date 2021-08-30 22:17
 * @description
 */
public class PromotionStrategyFacotry {
    private static Map<String, PromotionStrategy> PROMOTION_STRATEGY_MAP = new HashMap();

    static {
        PROMOTION_STRATEGY_MAP.put(PromotionKey.COUPON.name(), new CouponStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.CASHBACK.name(), new CashbackStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.GROUPBUY.name(), new GroupBuyStrategy());
    }

    private PromotionStrategy promotionStrategy;

    public static PromotionStrategy getPromotionStrategy(String promotionKey) {
        return Optional.ofNullable(PROMOTION_STRATEGY_MAP.get(promotionKey))
                .orElse(new EmptyStrategy());
    }

    private enum PromotionKey {
        COUPON, CASHBACK, GROUPBUY
    }
}
